import mongoengine

from academic.settings import MONGODB

class SubjectClassEmbedded(mongoengine.EmbeddedDocument):
    first_level = mongoengine.StringField(db_field='一级', max_length=50)
    second_level = mongoengine.StringField(db_field='二级', max_length=50)
    third_level = mongoengine.StringField(db_field='三级', max_length=50)

class SubjectCodeEmbedded(mongoengine.EmbeddedDocument):
    first_level = mongoengine.StringField(db_field='一级', max_length=50, null=True)
    second_level = mongoengine.StringField(db_field='二级', max_length=50, null=True)
    third_level = mongoengine.StringField(db_field='三级', max_length=50, null=True)

class FundChina(mongoengine.DynamicDocument):
    meta = {'collection': MONGODB.get('FOUNDATIONCHINA')}

    id = mongoengine.StringField(db_field='_id', max_length=50, primary_key=True)
    pic = mongoengine.StringField(db_field='负责人', max_length=50, required=True)
    org = mongoengine.StringField(db_field='单位', max_length=50)
    amount = mongoengine.StringField(db_field='金额(万)', max_length=20)
    projectNum = mongoengine.StringField(db_field='项目编号', max_length=50)
    type = mongoengine.StringField(db_field='项目类型', max_length=50)
    department = mongoengine.StringField(db_field='所属学部', max_length=50)
    approvalDate = mongoengine.StringField(db_field='批准年份', max_length=50)
    project = mongoengine.StringField(db_field='题目', max_length=50)
    exeTime = mongoengine.StringField(db_field='执行时间', max_length=50)
    subjectClass = mongoengine.EmbeddedDocumentField(db_field='学科分类', document_type=SubjectClassEmbedded)
    # subjectClass = mongoengine.DictField(db_field='subjectClass', max_length=50)
    subjectCode = mongoengine.EmbeddedDocumentField(db_field='学科代码', document_type=SubjectCodeEmbedded)
    # subjectCode = mongoengine.DictField(db_field='subjectCode', max_length=50)

    def __str__(self):
        return "项目id" + str(self.id) + "\t 姓名" + str(self.pic)

class FundEU(mongoengine.DynamicDocument):
    meta = {'collection': MONGODB.get('FOUNDATIONEU')}

    id = mongoengine.StringField(db_field='_id', max_length=50, primary_key=True)
    # id = mongoengine.ObjectIdField(db_field='_id', max_length=50, primary_key=True)
    frameworkProgramme = mongoengine.StringField(db_field='frameworkProgramme', max_length=50)
    title = mongoengine.StringField(db_field='title', max_length=300, required=True)
    startDate = mongoengine.StringField(db_field='startDate', max_length=20)
    endDate = mongoengine.StringField(db_field='endDate', max_length=50)
    objective = mongoengine.StringField(db_field='objective', max_length=5000)
    totalCost = mongoengine.StringField(db_field='totalCost', max_length=50)
    coordinator = mongoengine.StringField(db_field='coordinator', max_length=50)
    coordinatorCountry = mongoengine.StringField(db_field='coordinatorCountry', max_length=50, null=True)
    participants = mongoengine.StringField(db_field='participants', max_length=50)
    participantCountries = mongoengine.StringField(db_field='participantCountries', max_length=50)

    def __str__(self):
        return "项目id" + str(self.id) + "\t 项目名称" + str(self.title)

class FundUSA(mongoengine.DynamicDocument):
    meta = {'collection': MONGODB.get('FOUNDATIONUSA')}

    id = mongoengine.StringField(db_field='_id', max_length=50, primary_key=True)
    amount = mongoengine.StringField(db_field='项目资金', max_length=50)
    startDate = mongoengine.StringField(db_field='开始时间', max_length=50)
    endDate = mongoengine.StringField(db_field='结束时间', max_length=50)
    type = mongoengine.StringField(db_field='项目类别', max_length=50)
    title = mongoengine.StringField(db_field='项目名称', max_length=300, required=True)
    unit = mongoengine.StringField(db_field='负责单位', max_length=50)
    coordinator = mongoengine.StringField(db_field='负责人', max_length=50)
    participants = mongoengine.StringField(db_field='合作单位', max_length=50, null=True)
    abstract = mongoengine.StringField(db_field='项目摘要', max_length=5000)

    def __str__(self):
        return "项目id" + str(self.id) + "\t 项目名称" + str(self.title)
